package natsHelper

import "github.com/nats-io/nats.go"

var Conn *nats.Conn

func init() {
	conn, _ := nats.Connect(nats.DefaultURL)
	//c, _ := natsHelper.NewEncodedConn(nc, natsHelper.JSON_ENCODER)
	//defer conn.Close()
	Conn = conn
}

func Subscribe(subject string, cb nats.MsgHandler) {
	if Conn == nil {
		println("连接nats失败")
		return
	}
	_, err := Conn.Subscribe(subject, cb)
	if err != nil {
		println(err)
	}
}
